import axios from 'axios'
import qs from 'qs'
import { Dialog } from 'vant';
const service = axios.create({
  timeout: 10000,
});

// 发送请求配置
service.interceptors.request.use(
	config => {
	  // config.data = qs.stringify(config.data) // 如果是 form Data 传递数据的话加这句话
    //	  config.headers.userKey=appFun.getDevice()
	  return config
	},
	error => {
	    Promise.reject(error)
	}
)
// 接收请求配置
service.interceptors.response.use(res => {
    const code = res.data.responseCode
    if(code =='100'){
        return res.data
    }else{
			Dialog.alert({
			  message: res.data.messageList[0].message,
			}).then(() => {
			  
			});    	
      return Promise.reject(res.data.messageList[0].message)
    }	
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)


export default function () {
  return service
}
